#!/usr/bin/env node

import path from "path";
import { fileURLToPath } from "url";
import process from "process";
import { init } from "../bin/init.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageRoot = path.resolve(__dirname, "..");
const shouldSkipInit = process.env.NIKOU_SKIP_POSTINSTALL === "true";

async function run() {
    if (shouldSkipInit) {
        console.log("检测到 NIKOU_SKIP_POSTINSTALL=true，跳过 Nikou CLI postinstall 初始化。");
        return;
    }
    await init({
        mode: "npm-postinstall",
        projectDir: packageRoot
    });
    console.log("Nikou CLI postinstall 初始化完成，如需重新配置可执行 nb-init。");
}

run().catch((error) => {
    console.error("Nikou CLI postinstall 初始化失败:", error);
    process.exit(1);
});
